package 笔试.网易互娱;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/8/28-15:01
 * @version:1.0
 * @function:
 */
public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        while(T>0){
            LinkedList<MS> array = new LinkedList<>();
            int N = scanner.nextInt(),A = scanner.nextInt(),B = scanner.nextInt();
            while (N>0){
                MS ms = new MS(scanner.nextInt(), scanner.nextInt(), scanner.nextInt());
                array.add(ms);
                N--;
            }
            int fight = fight(array, A, B, 0);
            System.out.println(Math.abs(fight));
            T--;
        }
    }
    private static int challenge(MS ms,int A,int B,int H){
        int temp = H; // 主角生命值
        while (ms.H>0){
            int temp1 = A - ms.B; //ms 受到伤害
            if (temp1<=0)
                return -1;//打不死
            int temp2 = ms.A - B; //主角 受到伤害
            if (temp1>ms.H){
                temp += temp1 - ms.hashCode(); // 恢复值
                if (temp>H) temp = H; // 只能回复到100%
                temp -= temp2;
                ms.H = 0;
            }else {
                ms.H -= temp1;
                temp -=temp2;
            }
        }
        return temp;
    }
    private static int fight(LinkedList<MS> array, int a, int b,int h) {
        if (array.size()>0){
            MS ms = array.remove(0); // 出对的一个怪兽
            MS t = new MS(ms.A,ms.B,ms.H); // 出对的一个怪兽
            // 先打

            // 后打

        }
        return h;
    }
}
 class MS {
    int A;
    int B;
    int H;

    public MS(int a, int b, int h) {
        A = a;
        B = b;
        H = h;
    }
}
